import java.util.Properties;
import java.util.Set;

/**
 * @ClassName Demo01_Properties
 * @Description Properties 类基本方法
 * @Author Li
 * @Date 2022/8/11 14:54
 * @ModifyDate 2022/8/11 14:54
 * @Version 1.0
 */
public class Demo01_Properties {
    public static void main(String[] args) {
        // 创建属性集对象
        Properties properties = new Properties();

        // 添加键值对元素
        properties.setProperty("filename", "a.txt");
        properties.setProperty("length", "1527");
        properties.setProperty("location", "D:\\a.txt");

        // 打印属性集对象
        System.out.println(properties);

        // 通过键，获取属性值
        System.out.println(properties.getProperty("filename"));
        System.out.println(properties.getProperty("length"));
        System.out.println(properties.getProperty("location"));

        // 遍历属性集，获取所有键的集合
        Set<String> propertyNames = properties.stringPropertyNames();
        // 打印键值对
        for (String name : propertyNames) {
            System.out.println(name + "=" + properties.getProperty(name));
        }
    }
}
